window.onload = function(){

        //每个小圆点的宽度：
        var dot = $(".honer_slider .imagenav ul li").outerWidth(true);
        //小圆点的个数
        var sliderNum = $(".honer_slider .imagenav ul li").length;
        //设置imagenav总宽度：
        $(".imagenav").css("width", dot * sliderNum-17);
        var json0 = {"width":314,"height":246,"left":40,"top":50};
        var json1 = {"width":425,"height":333,"left":103,"top":37};
        var json2 = {"width":520,"height":407,"left":340,"top":0};
        var json3 = {"width":435,"height":333,"left":667,"top":37};
        var json4 = {"width":314,"height":246,"left":845,"top":50};

        //信号量
        var nowimg = 0;
        var lock = false; 
        var animateTime = 300;

        //定时器
        var timer = setInterval(rightButFunc, 2000);
        $(".honer_slider").mouseenter(function(){clearInterval(timer);});
        $(".honer_slider").mouseleave(function(){clearInterval(timer);
        timer = setInterval(rightButFunc, 2000);});
        
        //右按钮
        $(".rightbut").click(rightButFunc);
        function rightButFunc(){
            if(!$(".imagelist ul li").is(":animated") || lock){
                if(nowimg < sliderNum - 1){
                    nowimg++;
                }else{
                    nowimg = 0;
                }
                //小圆点
                $(".imagenav ul li").eq(nowimg).addClass("active").siblings().removeClass("active");
                //【交换位置】
                $(".imagelist .no1").animate(json0,animateTime);
                $(".imagelist .no2").animate(json1,animateTime);
                $(".imagelist .no3").animate(json2,animateTime);
                $(".imagelist .no4").animate(json3,animateTime);
                $(".imagelist .no0").animate(json4,animateTime);
                $(".imagelist .no0").css(json4);
                //【交换样式】
                var myno4 = $(".no4");
                $(".no0").attr("class","waiting");
                $(".no1").attr("class","no0");
                $(".no2").attr("class","no1");
                $(".no3").attr("class","no2");
                $(".no4").attr("class","no3");
                if(myno4.next().length != 0){
                    myno4.next().attr("class","no4");
                }else{
                    $(".imagelist ul li").eq(0).attr("class","no4");
                }
                $(".no4").css(json4);
            }
        }

        //左按钮
        $(".leftbut").click(leftButFunc);
        function leftButFunc(){
            if(!$(".imagelist ul li").is(":animated") || lock){
                if(nowimg > 0){
                    nowimg --;
                }else{
                    nowimg = sliderNum - 1;
                }
                $(".imagenav ul li").eq(nowimg).addClass("active").siblings().removeClass("active");
                $(".imagelist .no0").animate(json1,animateTime);
                $(".imagelist .no1").animate(json2,animateTime);
                $(".imagelist .no2").animate(json3,animateTime);
                $(".imagelist .no3").animate(json4,animateTime);
                $(".imagelist .no4").animate(json0,animateTime);
                $(".imagelist .no4").css(json0);
                var myno0 = $(".no0");
                $(".no4").attr("class","waiting");
                $(".no3").attr("class","no4");
                $(".no2").attr("class","no3");
                $(".no1").attr("class","no2");
                $(".no0").attr("class","no1");
                if(myno0.prev().length != 0){
                    myno0.prev().attr("class","no0");
                }else{
                    $(".imagelist ul li:last").attr("class","no0");
                }
                $(".no0").css(json0);
            }
        }

        // 小圆点的点击业务
        $(".imagenav ul li").click(function(){
                lock = true; 
                var index = $(this).index(); 
                if(index > nowimg){
                    var number = index - nowimg;
                    if (number > 1) {
                        animateTime = 100
                    }
                    for(var i = 0 ; i < number ; i++){
                        rightButFunc()
                    }
                }else{
                    var number = nowimg - index;
                    if (number > 1) {
                        animateTime = 100
                    }
                    for(var i = 0 ; i < number ; i++){
                        leftButFunc()
                    }
                }
                animateTime = 300
                lock = false
        });

        //点击图片的业务
        $(".imagelist ul li").click(function(){
                // var beifen = animateTime;
                // animateTime = 300;
                // lock = true; 
                // var index = $(this).index() - 2;
                // index = index <= 0 ? 5 + index : index; 
                // nowimg >= 5 ? nowimg = 0:nowimg;
                
                // if(index > nowimg){
                //     var number = index - nowimg;
                //     number > 1 ? animateTime = 100:animateTime = 300;
                //     for(var i = 1 ; i <= number ; i++){
                //         rightButFunc();
                //     }
                // }else{
                //     var number = nowimg - index;
                //     number >= 1 ? animateTime = 100:animateTime = 300;
                //     for(var i = 1 ; i <= number ; i++){
                //         leftButFunc();
                //     }
                // }
                // lock = false; 
                // animateTime = beifen;
                // nowimg = index;
        });

    }